<template>
	<view class="mainPage content" :style="{'padding-top': `${$store.state.safeArea.top || 0}px`, 'padding-bottom': `${$store.state.safeArea.bottom || 0}px`}">
		<public-head :title="title"></public-head>
		<view style="height: 10rpx;"></view>
		<view class="box">
			<u-field v-model="mobile" label="新手机号:" placeholder="请填写新手机号">
			</u-field>
			<u-field v-model="codes" label="验证码:" placeholder="请输入验证码">
				<u-button size="mini" slot="right" type="warning" @click="getCode">{{codeText}}</u-button>
			</u-field>
			<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
		</view>
		<view class="but" @click="determine">
			<button>确定</button>
		</view>
	</view>
</template>
<script>
var that
import publicHead from "@/components/publicHead/publicHead.vue"
export default {
	components: {
		publicHead
	},
	data() {
		return {
			title: "更换手机号码",
			mobile: '',
			code: '',
			codes: '',
			codeText: '',
			timer: null,
			sys_link: ''
		}
	},
	onLoad(e) {
		that = this
		that.sys_link = e.data
		console.log('接受到的数据', e.data)
	},
	methods: {
		codeChange(text) {
			this.codeText = text;
		},
		getCode() {
			if (this.$refs.uCode.canGetCode) {
				that.$postAjax1('Doctor_send_code', {
					status: 3,
					phone: that.mobile,
					source: 2
				}, function (data) {
					that.code = data.data.code
					var code = data.data.code
					if (code == 1) {
						setTimeout(() => {
							uni.hideLoading();
							// 通知验证码组件内部开始倒计时
							that.$refs.uCode.start();
						}, 1000);
						console.log('获取到验证码')
					}
					console.log(data);
				})
			} else {
				this.$u.toast('倒计时结束后再发送');
			}
		},
		determine() {
			// uni.reLaunch({
			// 		url:'../../../pages/mine/mine'
			// })
			that.$postAjax1('PetDoctor_Center_phoneNum', {
				upload_doctorphoneNum: that.mobile,
				input_ver_code: that.codes,
				sys_link: that.sys_link
			}, function (data) {
				uni.showToast({
					title: '提交成功',
					duration: 1000
				});
				this.timer = setTimeout(() => {
					uni.navigateBack({
						delta: 2
					});
					// 这里添加您的逻辑	
					// uni.navigateTo({
					// 	url:'./setup'
					// })
				}, 1000)
			})
		}
	},
	onUnload() {
		if (this.timer) {
			clearTimeout(this.timer);
			this.timer = null;
		}
	}
}
</script>
<style scoped lang="scss">
.content {
	width: 100vw;
	height: 100vh;
	background: #f6f6f6;
	position: relative;
	.box {
		background-color: #ffffff;
		//margin-top: 30rpx;
	}
	.but {
		width: 100%;
		position: absolute;
		top: 300rpx;
		button {
			width: 90%;
			background: linear-gradient(219deg, #ff9331 0%, #fe7600 100%);
			border-radius: 8rpx;
			font-weight: 400;
			color: #ffffff;
		}
	}
}
</style>
